﻿using FairyGUI;
using System;

/// <summary>
/// 登录界面UI
/// </summary>
public class UILoginWindow : UIBaseWindow {

    /// <summary>
    /// 登录按钮
    /// </summary>
    GButton _loginBtn;
    /// <summary>
    /// 用户协议按钮
    /// </summary>
    GButton _agreementBtn;
    /// <summary>
    /// 平台编号输入控件（该控件在没有接入第三方登录的时候使用）
    /// </summary>
    GTextInput _openidInput;

    public UILoginWindow()
    {
        // 初始化界面
        UIPackage.AddPackage("UI/登录界面");

        base.Init(UIPackage.CreateObject("登录界面", "登录界面").asCom);

        _loginBtn = uiComp.GetChild("登录按钮").asButton;
        _loginBtn.onClick.Add(()=> {
            AudioController.inst.PlayUIClickEffect();
            GameController.inst.EnqueueMessage(
                    new BaseProceduar.Message(Commands.CMD_CTRL_BUTTON_CLICKED, GameCommands.CMD_CTRL_LOGIN)
                    );
        });

        _agreementBtn = uiComp.GetChild("用户协议").asButton;
        _agreementBtn.onChanged.Add(()=> {
            AudioController.inst.PlayUIClickEffect();
        });
        agreementOk = true;

        _openidInput = uiComp.GetChild("平台编号输入").asTextInput;
    }

    public override void OnExit()
    {
        uiComp.Dispose();
        UIPackage.RemovePackage("UI/登录界面");
    }

    /// <summary>
    /// 获取/设置是否同意用户协议
    /// </summary>
    public bool agreementOk {
        set { _agreementBtn.selected = value; }
        get { return _agreementBtn.selected; }
    }

    /// <summary>
    /// 获取用户输入的平台编号
    /// </summary>
    public string openid { get { return _openidInput.text; } }

    /// <summary>
    /// 隐藏平台编号输入控件
    /// </summary>
    public void hiddenOpenidInput()
    {
        _openidInput.visible = false;
    }
}
